from django.db import models

# Create your models here.

# 商品表,商品名称，商品价格，商品图片，商品描述，商品评分，商品分类,要有verbose_name,除了name全可以为null和blank
class Goods(models.Model):
    name = models.CharField(max_length=100, verbose_name='商品名称')
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='商品价格', null=True, blank=True)
    images = models.ImageField( verbose_name='商品图片', null=True, blank=True,upload_to='images/')
    description = models.TextField(verbose_name='商品描述', null=True, blank=True)
    rating = models.DecimalField(max_digits=3, decimal_places=2, verbose_name='商品评分', null=True, blank=True)
    category = models.CharField(max_length=100, verbose_name='商品分类', null=True, blank=True)
    is_recommended = models.BooleanField(default=False, verbose_name='是否每日推荐')

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '商品'
        verbose_name_plural = verbose_name
        db_table = 'content_goods'



# 用户评分
class UserRating(models.Model):
    rating = models.DecimalField(max_digits=3, decimal_places=2, verbose_name='评分')
    user = models.ForeignKey('login.User', on_delete=models.SET_NULL, verbose_name='用户',null=True,blank=True)
    goods = models.ForeignKey('Goods', on_delete=models.SET_NULL, verbose_name='商品',null=True,blank=True)

    def __str__(self):
        return f'{self.user} - {self.goods} - {self.rating}'

    class Meta:
        verbose_name = '用户评分'
        verbose_name_plural = verbose_name
        db_table = 'UserRating'


# 用户购物
class UserShopping(models.Model):
    user = models.ForeignKey('login.User', on_delete=models.SET_NULL, verbose_name='用户',null=True,blank=True)
    goods = models.ForeignKey('Goods', on_delete=models.SET_NULL, verbose_name='商品',null=True,blank=True)

    def __str__(self):
        return f'{self.user} - {self.goods} '

    class Meta:
        verbose_name = '用户购物'
        verbose_name_plural = verbose_name
        db_table = 'UserShopping'
